<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('上传图像鉴黄')" />
	<th:block th:include="include :: cropbox-css" />
</head>
<body class="white-bg" style="margin-top:-10px">
    <div class="container"> 
       <div class="imageBox" style="width:400px;height:400px"> 
        	<div class="thumbBox" style="top: 0; left: 0; width:100%; height:100%; margin-top:0; margin-left:0"></div> 
	        <div class="spinner" style="display: none;">Waiting for the upload</div> 
	   </div> 
	   <div class="action"> 
	       <div class="new-contentarea tc">
	           <a href="javascript:void(0)" class="upload-img"> <label for="avatar">上传图像</label> </a> 
	           <input type="file" class="" name="avatar" id="avatar" accept="image/*"/>
	       </div> 
	       <input type="button" id="btnZoomIn" class="Btnsty_peyton" value="+" /> 
	   	   <input type="button" id="btnZoomOut" class="Btnsty_peyton" value="-" /> 
	   </div> 
	   <div class="cropped"></div> 
    </div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: cropbox-js" />
<script type="text/javascript">
var cropper;
 $(window).load(function() {
    var options = {
  		thumbBox: '.thumbBox',
        spinner: '.spinner'
    }
     cropper = $('.imageBox').cropbox(options);
    
     $('#avatar').on('change', function() {
        var reader = new FileReader();
        reader.onload = function(e) {
            options.imgSrc = e.target.result;
            //根据MIME判断上传的文件是不是图片类型
            if((options.imgSrc).indexOf("image/")==-1){
                $.modal.alertWarning("文件格式错误，请上传图片类型,如：JPG，PNG后缀的文件。");
            } else {
                cropper = $('.imageBox').cropbox(options);
            }
        }
        reader.readAsDataURL(this.files[0]);
    }) 
    
	 
	$('#btnZoomIn').on('click', function(){
		cropper.zoomIn();
	})
	
	$('#btnZoomOut').on('click', function(){
		cropper.zoomOut();
	}) 
}); 

function submitHandler() {
	var prefix = ctx + "system/appNsfwPic";
    var img = cropper.getBlob();
    var formdata = new FormData();
    formdata.append("avatarfile", img);
    $.ajax({
        url: prefix + "/add",
        data: formdata,
        type: "post",
        processData: false,
        contentType: false,
        success: function(result) {
        	$.operate.saveSuccess(result);
        }
    })
} 
</script>
</body>
</html>
